home *** CD-ROM | disk | FTP | other *** search
- Path: oskar.Hagenuk.de!news
- From: berg@hagenuk.de (Jens Berg)
- Newsgroups: comp.lang.c
- Subject: Re: Another What does this do...
- Date: 20 Mar 1996 13:01:33 GMT
- Organization: Hagenuk Telecom GmbH
- Message-ID: <4iovjd$ime@oskar.Hagenuk.de>
- References: <4ijkrh$8t@apollo.isisnet.com>
- Reply-To: berg@hagenuk.de (Jens Berg)
- NNTP-Posting-Host: kst103_hat_jens_berg.hagenuk.de
- X-Newsreader: IBM NewsReader/2 v1.02
-
- In <4ijkrh$8t@apollo.isisnet.com>, aa254@ccn.cs.dal.ca (Bill Fraser) writes:
- >Hi! I've been trying mot of the weekend to make sense of Microsoft's
- >program to read Rich Text Formatted files. I got it from their site
- >with the V1.4 rtf documentation and am hoping to adapt it to be able
- >to extract text and attributes for displaying word processor text on
- >character based color terminals ( color, bold, blink, inverse video ).
- >
- >Asside from never having programmed in C before, I figured I was doing
- >quite well until I came across the following statement:
- >
- > pb = (char *)&dop;
- >
- >where pb and dop are defined as:
- > char *pb;
- >and
- > dop is structure DOP like this:
- >
- > typedef struct doc_prop
- > {
- > int xaPage;
- > ...
- > char flandscape;
- > } DOP;
- >
- As you said yourself, dop is a variable of structure DOP.
- &dop is the address of this var in memory or if you look at it the
- other way round it is a pointer to a location in memory, where a structure DOP
- is stored. Now this pointer is casted to a character pointer (that means, the compiler
- is forced to treat it as a charcter pointer) and assigned to the variable pb.
- You are now able to read the contents of your structure dop char by char, if you
- access *pb, *(pb+1), *(pb+2) etc. or (equivalent in this case) pb[0], pb[1], pb[2] etc.
-
- To do something like this is extremly unportable code and should be avoided, as
- the chars you read are dependent on how your machine is designed (little/big endian,
- RISC/CISC architecture), how your compiler represents structures in memory, if it
- uses packed structures etc.
-
- [Jens]
-
- Jens Berg
- Hagenuk GmbH, Kiel - Germany
- Phone: +49 431 8818 70020, email: berg@hagenuk.de
- #include <standard.disclaimer>
- I only speak for myself!
-
-